package club.vann.kafka.mock.service.strategy;

import club.vann.kafka.mock.kafka.KafkaProducer;
import club.vann.kafka.mock.util.AcceptorUtil;
import com.cyberx.lunyu.AcceptorOuterClass;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import org.springframework.stereotype.Component;

@Component
public class StrategyInitService extends StrategyAcceptorService {
  public StrategyInitService(KafkaProducer kafkaProducer) {
    super(kafkaProducer);
  }

  @Override
  public AcceptorOuterClass.Acceptor.RequestType requestType() {
    return AcceptorOuterClass.Acceptor.RequestType.NEW_GRAPH;
  }

  @Override
  public void input(AcceptorOuterClass.Acceptor.AcceptorRequest request) {
    String clientRequestId = request.getClientRequestId();
    String responseTopic = request.getTopic();

    Map<String, String> responseMap = new HashMap<>();
    responseMap.put("SYMBOL", "BTC/USDT-PairInventorySummaryAlpha-SingleInputKafkaOutput-9a62d4c8");
    responseMap.put("STRATEGY_SPEC", UUID.randomUUID().toString());

    AcceptorOuterClass.Acceptor.AcceptorResponse acceptorResponse =
        AcceptorUtil.ofResponse(
            clientRequestId,
            AcceptorOuterClass.Acceptor.Status.COMPLETED,
            responseTopic,
            "",
            responseMap);
    this.kafkaProducer.send(responseTopic, clientRequestId, acceptorResponse.toByteArray());
  }
}
